package com.example.javaui.slice.component;

import com.example.javaui.ResourceTable;
import com.example.javaui.Utils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.text.Font;
import ohos.agp.utils.TextAlignment;
import ohos.multimodalinput.event.KeyEvent;
import ohos.multimodalinput.event.RotationEvent;
import ohos.multimodalinput.event.TouchEvent;

public class TextSlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_component_text);

        // 将Text加粗
        Text textBold = (Text) findComponentById(ResourceTable.Id_text_bold);
        textBold.setFont(Font.DEFAULT_BOLD);

        // 文本框
        TextField tfUsername = (TextField) findComponentById(ResourceTable.Id_textfield_username);
        tfUsername.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int i, int i1, int i2) {
                Utils.log("文本框文本变化:" + s);
            }
        });

        // 时钟
        Clock clock = (Clock) findComponentById(ResourceTable.Id_clock);

        // 常规计时器
        TickTimer tickTimer = (TickTimer) findComponentById(ResourceTable.Id_ticktimer);
        tickTimer.start();

        // 倒计时
        TickTimer tickTimerCountDown = (TickTimer) findComponentById(ResourceTable.Id_ticktimer_countdown);
        tickTimerCountDown.setBaseTime(System.currentTimeMillis() + 30 * 1000);
        tickTimerCountDown.setFormat("倒计时:ss秒");
        tickTimerCountDown.start();
    }
}
